﻿using GalaSoft.MvvmLight;
using GalaSoft.MvvmLight.Command;
using GalaSoft.MvvmLight.Messaging;
using MoreEPG.Helper;
using System;

namespace MoreEPG.ViewModel
{
    
    public class CustomDialogBoxViewModel : ViewModelBase
    {
       
        public CustomDialogBoxViewModel()
        {
            InitCommands();
        }

        
        public const string InfoTextPropertyName = "InfoText";
        private string _InfoText;
        public string InfoText
        {
            get
            {
                return _InfoText;
            }

            set
            {
                if (_InfoText == value)
                {
                    return;
                }

               
                _InfoText = value;


                // Update bindings, no broadcast
                RaisePropertyChanged(InfoTextPropertyName);

                
            }
        }

        /// <summary>
        /// The <see cref="visibilityYes" /> property's name.
        /// </summary>
        public const string visibilityYesPropertyName = "visibilityYes";

        private bool _visibilityYes = false;

        /// <summary>
        /// Gets the visibilityYes property.
        /// TODO Update documentation:
        /// Changes to that property's value raise the PropertyChanged event. 
        /// This property's value is broadcasted by the Messenger's default instance when it changes.
        /// </summary>
        public bool visibilityYes
        {
            get
            {
                return _visibilityYes;
            }

            set
            {
                if (_visibilityYes == value)
                {
                    return;
                }

               
                _visibilityYes = value;

                // Update bindings, no broadcast
                RaisePropertyChanged(visibilityYesPropertyName);

                
            }
        }

        /// <summary>
        /// The <see cref="visibilityYes" /> property's name.
        /// </summary>
        public const string visibilityNoPropertyName = "visibilityNo";

        private bool _visibilityNo = false;

        /// <summary>
        /// Gets the visibilityYes property.
        /// TODO Update documentation:
        /// Changes to that property's value raise the PropertyChanged event. 
        /// This property's value is broadcasted by the Messenger's default instance when it changes.
        /// </summary>
        public bool visibilityNo
        {
            get
            {
                return _visibilityNo;
            }

            set
            {
                if (_visibilityNo == value)
                {
                    return;
                }


                _visibilityNo = value;

                // Update bindings, no broadcast
                RaisePropertyChanged(visibilityNoPropertyName);


            }
        }

        /// <summary>
        /// The <see cref="visibilityYes" /> property's name.
        /// </summary>
        public const string visibilityOkPropertyName = "visibilityOk";

        private bool _visibilityOk = false;

        /// <summary>
        /// Gets the visibilityYes property.
        /// TODO Update documentation:
        /// Changes to that property's value raise the PropertyChanged event. 
        /// This property's value is broadcasted by the Messenger's default instance when it changes.
        /// </summary>
        public bool visibilityOk
        {
            get
            {
                return _visibilityOk;
            }

            set
            {
                if (_visibilityOk == value)
                {
                    return;
                }


                _visibilityOk = value;

                // Update bindings, no broadcast
                RaisePropertyChanged(visibilityOkPropertyName);


            }
        }

        /// <summary>
        /// The <see cref="visibilityYes" /> property's name.
        /// </summary>
        public const string visibilityCancelPropertyName = "visibilityCancel";

        private bool _visibilityCancel = false;

        /// <summary>
        /// Gets the visibilityYes property.
        /// TODO Update documentation:
        /// Changes to that property's value raise the PropertyChanged event. 
        /// This property's value is broadcasted by the Messenger's default instance when it changes.
        /// </summary>
        public bool visibilityCancel
        {
            get
            {
                return _visibilityCancel;
            }

            set
            {
                if (_visibilityCancel == value)
                {
                    return;
                }


                _visibilityCancel = value;

                // Update bindings, no broadcast
                RaisePropertyChanged(visibilityCancelPropertyName);


            }
        }

        /// <summary>
        /// The <see cref="Image" /> property's name.
        /// </summary>
        public const string ImagePropertyName = "Image";

        private Uri _Image;

        /// <summary>
        /// Gets the Image property.
        /// TODO Update documentation:
        /// Changes to that property's value raise the PropertyChanged event. 
        /// This property's value is broadcasted by the Messenger's default instance when it changes.
        /// </summary>
        public Uri Image
        {
            get
            {
                return _Image;
            }

            set
            {
                if (_Image == value)
                {
                    return;
                }

               
                _Image = value;

                
                // Update bindings, no broadcast
                RaisePropertyChanged(ImagePropertyName);
               
            }
        }



        private Uri Info = new Uri("../Images/Info.png", UriKind.RelativeOrAbsolute);
        private Uri Question = new Uri("../Images/Question.png", UriKind.RelativeOrAbsolute);
        private Uri Error = new Uri("../Images/Error.png", UriKind.RelativeOrAbsolute);
        private Uri Alert = new Uri("../Images/Alert.png", UriKind.RelativeOrAbsolute);

        public CustomMessageBoxImage customMessageBoxImage
        {
            set
            {
                switch (value)
                {
                    case CustomMessageBoxImage.Error:
                        this.Image = Error;
                        break;
                    case CustomMessageBoxImage.Information:
                        this.Image = Info;
                        break;
                    case CustomMessageBoxImage.Question:
                        this.Image = Question;
                        break;
                    case CustomMessageBoxImage.Alert:
                        this.Image = Alert;
                        break;
                    case CustomMessageBoxImage.None:
                        break;
                    default:
                        break;
                }
            }
        }

        public CustomMessageBoxButton customMessageBoxButton
        {
            set
            {
                this.visibilityOk = false;
                this.visibilityCancel = false;
                this.visibilityYes = false;
                this.visibilityNo = false;
                switch (value)
                {
                    case CustomMessageBoxButton.OK:
                        this.visibilityOk = true;
                        break;
                    case CustomMessageBoxButton.OKCancel:
                        this.visibilityOk = true;
                        this.visibilityCancel = true;
                        break;
                    case CustomMessageBoxButton.YesNo:
                        this.visibilityYes = true;
                        this.visibilityNo = true;
                        break;
                    case CustomMessageBoxButton.YesNoCancel:
                        this.visibilityYes = true;
                        this.visibilityNo = true;
                        this.visibilityCancel = true;
                        break;
                    default:
                        break;
                }
            }
        }

        public CustomDialogMessageResult result { get; set; }


        public RelayCommand Yes
        {
            get;
            private set;
        }

        public RelayCommand No
        {
            get;
            private set;
        }

        public RelayCommand Ok
        {
            get;
            private set;
        }

        public RelayCommand Cancel
        {
            get;
            private set;
        }

        private void InitCommands()
        {

            this.Yes = new RelayCommand(
                () => OnYes());

            this.No = new RelayCommand(
                () => OnNo());

            this.Ok = new RelayCommand(
                () => OnOk());

            this.Cancel = new RelayCommand(
                () => OnCancel());
        }

        private void OnYes()
        {
            this.result = CustomDialogMessageResult.Yes;
            Messenger.Default.Send("CloseMB");
        }

        private void OnNo()
        {
            this.result = CustomDialogMessageResult.No;
            Messenger.Default.Send("CloseMB");
        }

        private void OnOk()
        {
            this.result = CustomDialogMessageResult.OK;
            Messenger.Default.Send("CloseMB");
        }

        private void OnCancel()
        {
            this.result = CustomDialogMessageResult.Cancel;
            Messenger.Default.Send("CloseMB");
        }
    }
}